import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '物料名称',		name: 'mate_name' },
			{ label: '物料编号',		name: 'mate_number' },
			{ label: '物料分类',		name: 'mate_type', 	type:'select', loading:true},
			{ label: '警告类型',		name: 'warn_type', 	type:'select', data:[{ name:'数量不足', value: '1' }, { name:'即将过期', value: '2' }] },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	
	// 获取下拉数据
	getSelect = async () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 物料分类
			$fn.setRow(forms, 'mate_type', await f.getDisCache({ code:26000 } ) )
			// 
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'material/warning')
	
	// 表单
	cols = [
		{ title: '物料名称', 		dataIndex: 'mate_name', 		width:150 },
		{ title: '物料编号', 		dataIndex: 'mate_number', 		width:200 },
		{ title: '物料类型', 		dataIndex: 'type', 				width:200 },
		{ title: '剩余量', 			dataIndex: 'unuse_qty', 		width:220 },
		{ title: '距离过期（天）', 	dataIndex: 'shelf_life', 		width:220 },
		{ title: '保质期', 			dataIndex: 'expire_date_num', 	width:220 },
	]

	render(){
		return (
			<>
				<Page title='库存警告列表'>
					{/* 搜索 */}
					{ SearchForm.call(this)  }
					{/* 表格 */}
					{ Table.call(this, { type: -1, isInit:window.isInit }) }
				</Page>
			</>
		)
	}
}

export default Index